package cn.itcast.bos.web.action.base;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;

import cn.itcast.bos.domain.base.Standard;
import cn.itcast.bos.service.base.IStandardService;
import cn.itcast.bos.utils.BaseAction;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

@ParentPackage("json-default")
@Namespace("/")
@Controller
@Scope("prototype")
public class StandardAction extends BaseAction<Standard> {

	
	// 属性注入
	@Autowired
	private IStandardService standardService;
	//添加收派
	@Action(value = "standard_save", results = { @Result(name = "success", type = "redirect", location = "/pages/base/standard.html") })
	public String save() {

		standardService.save(model);
		return SUCCESS;
	}
	
	/*//属性注入
	private int rows;
	private int page;
	public void setRows(int rows) {
		this.rows = rows;
	}
	public void setPage(int page) {
		this.page = page;
	}*/
	
	//查询分页数据
	@Action(value="standard_pageQuery",results={@Result(name="success",type="json")})
	public String pageQuery(){
		//调用业务层,查询数据结果
		Pageable pageable=new PageRequest(page-1,rows);
		Page<Standard> pageDate=standardService.findPageDate(pageable);
		/*//创建map集合
		Map<String,Object>map=new HashMap<String,Object>();
		map.put("total", pageDate.getTotalElements());
		map.put("rows", pageDate.getContent());
		//值栈
		ActionContext.getContext().getValueStack().push(map);*/
		
		pushPageDataToValueStack(pageDate);
		return SUCCESS;
	}
	
	//查询取派标准
	@Action(value="standard_findAll",results={@Result(name="success",type="json")})
	public String findAll(){
		//调用业务层,查询数据结果
		List<Standard>list=standardService.findAll();
		//值栈
		ActionContext.getContext().getValueStack().push(list);
		return SUCCESS;
	}
	
	
	
	
	
}
